package com.liang.stream;

import java.util.ArrayList;
import java.util.function.Consumer;
import java.util.function.Predicate;

public class ArrayStreamDemo {
    public static void main(String[] args) {
        //创建新的arraylist对象
        ArrayList<String> arr = new ArrayList<>();

        //添加数据
        arr.add("aaa");
        arr.add("bbb");
        arr.add("ccc");
        arr.add("ddd");
        arr.add("eee");

        //创建stream流
        arr.stream().filter(new Predicate<String>() {
            @Override
            public boolean test(String s) {
                return  s.length() == 3;
            }
        }).forEach(new Consumer<String>() {
            @Override
            public void accept(String s) {
                System.out.println(s);
            }
        });
        System.out.println("============================");
        arr.stream().filter(s->s.length()==3).forEach(s-> System.out.println(s));
    }
}
